﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
using System.Collections.Generic;
using System.Globalization;

public partial class JobseekerProfile_EditTechnologyUsed : System.Web.UI.Page
{
    int ProfileId = 0, UserId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserId"] == null)
                Response.Redirect("Default.aspx");
            string roleid = "";
            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            if (Request.QueryString["roleid"] != null)
                roleid = clsEncryptionDecryption.Decrypt(Request.QueryString["roleid"].ToString());
            if (roleid == "4")
            {
                IN_TB_USER objIN_TB_USER = new IN_TB_USER();
                if (Session["UserId"] != null)
                    objIN_TB_USER = objclsUserLoginDAL.GetUserByID(Convert.ToInt32(Session["UserId"].ToString()));
                if (objIN_TB_USER != null)
                {
                    Session["UserId"] = objIN_TB_USER.ID;
                    dvAutority.Visible = true;
                    ddlTechnologyExperience.Items.Clear();
                    ddlTechnologyExperience.AppendDataBoundItems = true;
                    ddlTechnologyExperience.Items.Add("Select");
                    ddlTechnologyExperience.Items[0].Value = "0";
                    for (int i = 1; i <= 60; i++)
                    {
                        ddlTechnologyExperience.Items.Add(i.ToString());
                        ddlTechnologyExperience.Items[i].Value = i.ToString();
                    }
                    ddlTechnologyExperience.DataBind();
                    FillSkillsUsed(objIN_TB_USER.ID);
                }
            }
        }
    }

    protected void btnResumeSkills_Click(object sender, EventArgs e)
    {
        try
        {
            List<IN_TB_RRESUME_SKILL> objIN_TB_RRESUME_SKILLList = new List<IN_TB_RRESUME_SKILL>();
            objIN_TB_RRESUME_SKILLList = (List<IN_TB_RRESUME_SKILL>)Session["objIN_TB_RRESUME_SKILLList"];

            clsResumeSkillsDAL objclsResumeSkillsDAL = new clsResumeSkillsDAL();
            foreach (IN_TB_RRESUME_SKILL ibjIN_TB_RRESUME_SKILL in objIN_TB_RRESUME_SKILLList)
            {
                objclsResumeSkillsDAL = new clsResumeSkillsDAL();
                if (Session["UserId"] != null)
                    ibjIN_TB_RRESUME_SKILL.USERID = Convert.ToInt32(Session["UserId"]);
                ibjIN_TB_RRESUME_SKILL.CREATED_BY = 1;
                ibjIN_TB_RRESUME_SKILL.MODIFIED_BY = 1;
                int resumeSkillid = objclsResumeSkillsDAL.SaveResumeSkills(ibjIN_TB_RRESUME_SKILL);
            }
            if (Request.QueryString["roleid"] != null && Session["UserId"] != null)
            {
                Response.Redirect("JobseekerPrieview.aspx?roleid=" + Request.QueryString["roleid"].ToString());
            }
            else
            {
                Session["RoleId"] = null;
                Response.Redirect("JobSeekerLogin.aspx");
            }
        }
        catch (Exception)
        {

            throw;
        }

    }

    protected void BtnAddSkills_Click(object sender, EventArgs e)
    {
        List<IN_TB_RRESUME_SKILL> objIN_TB_RRESUME_SKILLList = new List<IN_TB_RRESUME_SKILL>();
        objIN_TB_RRESUME_SKILLList = (List<IN_TB_RRESUME_SKILL>)Session["objIN_TB_RRESUME_SKILLList"];
        IN_TB_RRESUME_SKILL objIN_TB_RRESUME_SKILL = new IN_TB_RRESUME_SKILL();

        objIN_TB_RRESUME_SKILL.TECHNOLOGY = txtTechnology.Text.Trim();
        objIN_TB_RRESUME_SKILL.LAST_USED = DateTime.ParseExact(txtLastUsed.Text, "dd-MMM-yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None);
        objIN_TB_RRESUME_SKILL.EXPERIENCE = Convert.ToInt32(ddlTechnologyExperience.SelectedValue);
        objIN_TB_RRESUME_SKILLList.Add(objIN_TB_RRESUME_SKILL);
        Session["objIN_TB_RRESUME_SKILLList"] = objIN_TB_RRESUME_SKILLList;
        grdTechnology.DataSource = objIN_TB_RRESUME_SKILLList;
        grdTechnology.DataBind();

        

    }

    protected void FillSkillsUsed(int UserId)
    {
        try
        {
            List<IN_TB_RRESUME_SKILL> objIN_TB_RRESUME_SKILLList = new List<IN_TB_RRESUME_SKILL>();
            clsResumeSkillsDAL objclsResumeSkillsDAL = new clsResumeSkillsDAL();
            objIN_TB_RRESUME_SKILLList = objclsResumeSkillsDAL.GetResumeSkillsByUserId(UserId);
            if (objIN_TB_RRESUME_SKILLList != null)
            {
                grdTechnology.DataSource = objIN_TB_RRESUME_SKILLList;
                grdTechnology.DataBind();
                Session["objIN_TB_RRESUME_SKILLList"] = objIN_TB_RRESUME_SKILLList;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
}
